package com.lyn.policy.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.lyn.policy.domain.PolicyDoc;
import com.lyn.policy.service.PolicyDocService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping(path = "/api/v1/policy")
@Api(tags = "api.v1.policy", description = "API")
public class PolicyDocController {

	@Autowired
	PolicyDocService policyDocService;
	
	
	
	/**************************************************查询***************************************************/
	

	/**
	 * 简单查询，使用?占位符
	 */
	@RequestMapping(method = RequestMethod.GET, value="/select1")
	@ApiOperation(value = "简单查询，使用?占位符", nickname = "select1", notes="xxx")
	@ResponseStatus(code = HttpStatus.OK)
	public List<PolicyDoc> select1(
			@RequestParam(required = true) 
			@ApiParam(required = true, name = "deptname", value = "单位名称") String deptname, 
			@RequestParam(required = true) 
			@ApiParam(required = true, name = "name", value = "文件名称") String name 
			) {
		return policyDocService.select1(deptname, name);
	}
	
	/**
	 * 简单查询，使用#para(0)占位符
	 */
	@RequestMapping(method = RequestMethod.GET, value="/select2")
	@ApiOperation(value = "简单查询，使用#para(0)占位符", nickname = "select2", notes="xxx")
	@ResponseStatus(code = HttpStatus.OK)
	public List<PolicyDoc> select2(
			@RequestParam(required=true, name="no") 
			@ApiParam(required=true, name="no", value="文件编号", defaultValue="11") Integer no,
			@RequestParam(required=true, name="authodId") 
			@ApiParam(required=true, name="authodId", value="作者id", defaultValue="3") Integer authorId,
			@RequestParam(name = "pageNumber",required = false)
	        @ApiParam(name = "pageNumber",required = false,value = "当前页码",defaultValue = "1") Integer pageNumber, 
	        @RequestParam(name = "pageSize",required = false)
	        @ApiParam(name = "pageSize",required = false,value = "每页行数",defaultValue = "15") Integer pageSize 
			) {
		return policyDocService.select2(no, authorId, pageNumber, pageSize);
	}
	
	/**
	 * 简单查询，使用#para(deptname)占位符
	 */
	@RequestMapping(method = RequestMethod.GET, value="/select3")
	@ApiOperation(value = "简单查询，使用#para(deptname)占位符", nickname = "select3", notes="xxx")
	@ResponseStatus(code = HttpStatus.OK)
	public List<PolicyDoc> select3(
			@RequestParam(required=true, name="deptname") 
			@ApiParam(required=true, name="deptname", value="单位名称", defaultValue="南宁市国土局") String deptname,
			@RequestParam(required=true, name="no") 
			@ApiParam(required=true, name="no", value="文档id", defaultValue="11") Integer no,
			@RequestParam(name = "pageNumber",required = false)
	        @ApiParam(name = "pageNumber",required = false,value = "当前页码",defaultValue = "1") Integer pageNumber, 
	        @RequestParam(name = "pageSize",required = false)
	        @ApiParam(name = "pageSize",required = false,value = "每页行数",defaultValue = "15") Integer pageSize 
			) {
		return policyDocService.select3(deptname, no, pageNumber, pageSize);
	}
	
	/**
	 * like查询
	 */
	@RequestMapping(method = RequestMethod.GET, value="/selectlike")
	@ApiOperation(value = "like查询", nickname = "selectlike", notes="xxx")
	@ResponseStatus(code = HttpStatus.OK)
	public List<PolicyDoc> selectLike(
			@RequestParam(required=true, name="deptname") 
			@ApiParam(required=true, name="deptname", value="单位名称", defaultValue="南宁") String deptname,
			@RequestParam(name = "pageNumber",required = false)
	        @ApiParam(name = "pageNumber",required = false,value = "当前页码",defaultValue = "1") Integer pageNumber, 
	        @RequestParam(name = "pageSize",required = false)
	        @ApiParam(name = "pageSize",required = false,value = "每页行数",defaultValue = "15") Integer pageSize 
			) {
		return policyDocService.selectLike(deptname, pageNumber, pageSize);
	}
	
	/**
	 * in查询
	 */
	@RequestMapping(method = RequestMethod.GET, value="/selectin")
	@ApiOperation(value = "in查询", nickname = "selectin", notes="xxx")
	@ResponseStatus(code = HttpStatus.OK)
	public List<PolicyDoc> selectIn(
			@RequestParam(required=true, name="ids") 
			@ApiParam(required=true, name="ids", value="id列表，逗号分隔") String ids,
			@RequestParam(name = "pageNumber",required = false)
	        @ApiParam(name = "pageNumber",required = false,value = "当前页码",defaultValue = "1") Integer pageNumber, 
	        @RequestParam(name = "pageSize",required = false)
	        @ApiParam(name = "pageSize",required = false,value = "每页行数",defaultValue = "15") Integer pageSize 
			) {
		return policyDocService.selectIn(ids, pageNumber, pageSize);
	}
	
	/**
	 * 复杂where查询
	 */
	@RequestMapping(method = RequestMethod.GET, value="/selectwhere")
	@ApiOperation(value = "复杂where查询", nickname = "selectwhere", notes="xxx")
	@ResponseStatus(code = HttpStatus.OK)
	public List<PolicyDoc> selectWhere(
			@RequestParam(required=true, name="deptname") 
			@ApiParam(required=true, name="deptname", value="单位名称", defaultValue="南宁市国土局") String deptname,
			@RequestParam(required=true, name="name") 
			@ApiParam(required=true, name="name", value="文档名称", defaultValue="《关于加快南宁市人力资源服务业发展的实施办法》 （南府规〔2018〕20号，自印发之日施行）") String name,
			@RequestParam(name = "pageNumber",required = false)
	        @ApiParam(name = "pageNumber",required = false,value = "当前页码",defaultValue = "1") Integer pageNumber, 
	        @RequestParam(name = "pageSize",required = false)
	        @ApiParam(name = "pageSize",required = false,value = "每页行数",defaultValue = "15") Integer pageSize 
			) {
		return policyDocService.selectWhere(deptname, name, pageNumber, pageSize);
	}
	
	/**
	 * 简单更新
	 */
	@RequestMapping(method = RequestMethod.GET, value="/update")
	@ApiOperation(value = "update", nickname = "update", notes="xxx")
	@ResponseStatus(code = HttpStatus.OK)
	public String update(
			@RequestParam(required=true, name="content") 
			@ApiParam(required=true, name="content", value="内容") String content,
			@RequestParam(required=true, name="deptname") 
			@ApiParam(required=true, name="deptname", value="单位名称") String deptname,
			@RequestParam(required=true, name="no") 
			@ApiParam(required=true, name="no", value="文件编号", defaultValue="11") Integer no,
			@RequestParam(name = "pageNumber",required = false)
	        @ApiParam(name = "pageNumber",required = false,value = "当前页码",defaultValue = "1") Integer pageNumber, 
	        @RequestParam(name = "pageSize",required = false)
	        @ApiParam(name = "pageSize",required = false,value = "每页行数",defaultValue = "15") Integer pageSize 
			) {
		return policyDocService.update(content, deptname, no);
	}
	
	
}
